<?php 
/**
 * @todo 显示好友列表页面
 * @author 马超
 */
define('_VIEW_MODEL_','default');
session_start();
require_once("./init.php");
$uId      = isset($_SESSION['id'])?$_SESSION['id']:null; //用户id

if(empty($uId)){ //验证没有登录禁止访问
	errorPrompt('no_login','login.php');exit;
}

//分页
$page   = (isset($page) && intval($page)>0)?intval($page):1; //当前页码
$perNum = 5; //每页显示记录数 
//总记录数
$csql   = "select count(B.id) as count from {$telper}friend as A join {$telper}user as B
		   on (A.friendid = B.id) where A.userid='$uId' and A.state='0' and B.state='0'";
$count  = $db->getRow($csql);
$count  = $count['count']; //总记录数
$page   = min($page,ceil($count/$perNum));
$page   = $page>0?$page:1;
$start  = $perNum*($page - 1);

$sql = "select B.id,B.name,B.lasttime from {$telper}friend as A join {$telper}user as B
		on (A.friendid = B.id) where A.userid='$uId' and A.state='0' and B.state='0' limit $start,$perNum";
$friendList = $db->getAll($sql);
if(!empty($friendList)){
	foreach ($friendList as &$val){
		$val['lasttime'] = date("Y-m-d H:m",$val['lasttime']);
	}
}
//调用分页类
$pageObj = new Page($count,$perNum,$smartyObj);

$smartyObj->assign('friendlist',$friendList);
header("Content-type:text/vnd.wap.wml;charset=utf-8");
$smartyObj->display('friendlist.tpl');
?>